package org.example.j2024_11_4;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/t1")
@RestController
public class TestController {
     @RequestMapping("/r1")
    public String r1(){
         return "你好";
     }
     @RequestMapping("/r2")
    public String r2(String name , Integer age){
         return "name: "+name + " age:"+age;
     }


     @RequestMapping("/r3")
    public String r3( User  user){
         return user.toString();
     }

     @RequestMapping("/r4")
    public String r4(@RequestParam(value = "user" , required = false) String name){
         return "name: "+name ;
     }

     @RequestMapping("/r5")
    public String r5(Integer[] arr){
         return Arrays.toString(arr);
     }

     @RequestMapping("/r6")
    public String r6(@RequestParam(value = "list" , required = false) List<Integer> l1){
         return l1==null?"list为null ":l1.toString();
     }

      @RequestMapping("/r7")
    public String r7(@RequestBody(required = false) User user){
         return user==null?"没有json数据": user.toString();
      }

      @RequestMapping("/r8/{name}/{age}")
     public String r8(@PathVariable(value = "name" , required = false) String name ,
                       @PathVariable(value = "age" , required = false) Integer age ){
         return "name:"+name + "age: "+age ;
      }
      @RequestMapping("/r9")
     public String r9(@RequestPart (value = "f1",required = false) MultipartFile file  ) throws IOException {
          if(file == null)return "没有文件";
          file.transferTo(new File("E:/kun.jpg"));

         return file.getOriginalFilename();
      }



 }
